<template>
    <div class="qingwu">
        <div class="admin_table_page_title">
            <a-button @click="$router.back()" class="float_right" icon="arrow-left">返回</a-button>
            方案 {{type}}
        </div>
        <div class="unline underm"></div>
        <div class="admin_form">
            <a-form-model :label-col="{ span: 2 }" :wrapper-col="{ span: 12 }">
                <a-form-model-item label="* 方案标题 :">
                    <a-input v-model="info.plan_title"></a-input>
                </a-form-model-item>


                <a-form-model-item label="* 方案类型 :">
                    <a-radio-group v-model="info.alarm_type" :default-value="info.alarm_type">
                        <a-radio v-model="alarm_type"  :value="1">电费</a-radio>
                        <a-radio v-model="alarm_type"  :value="2">水费</a-radio>
                        <a-radio v-model="alarm_type"  :value="3">物业费</a-radio>
                    </a-radio-group>
                </a-form-model-item>


                <a-form-model-item  label="* 提前报警余额 :" :wrapper-col="{ span: 5 }">
                    <a-input  v-model="info.early_warning_balance" placeholder=""></a-input>
                </a-form-model-item>

                <a-form-model-item label="* 报警余额 :" :wrapper-col="{ span: 5 }">
                    <a-input v-model="info.alarm_balance"></a-input>
                </a-form-model-item>

                <a-form-model-item label="* 最大报警次数 :"  :wrapper-col="{ span: 5 }">
                    <a-input v-model="info.max_times"></a-input>
                </a-form-model-item>
                <a-form-model-item label="* 报警时间间隔 :" :wrapper-col="{ span: 5 }">
                    <a-input v-model="info.alarm_time"></a-input>
                </a-form-model-item>

                <a-form-item label="描述">
                    <wang-editor :contents="info.remarks" @goods_content="goods_content_fun" />
                    <!--<a-input v-model="info.remarks" type="textarea" />-->
                </a-form-item>

                <a-form-model-item :wrapper-col="{ span: 12, offset: 5 }">
                    <a-button type="primary" @click="handleSubmit">提交</a-button>
                </a-form-model-item>
            </a-form-model>

        </div>
    </div>
</template>

<script>
    import wangEditor from "@/components/wangeditor"
export default {
    components: {wangEditor},
    props: {},
    data() {
      return {
          info:{
          },
          id:0,
          community_lists:[],    // 小区列表
          default_community_id:'请选择小区',   // 默认
          // alarm_type:1, // 商品详情，
          type:'编辑'

      };
    },
    watch: {},
    computed: {},
    methods: {
        handleSubmit(){
            // 验证代码处
            if(this.$isEmpty(this.info.plan_title)){
                return this.$message.error('方案标题不能为空');
            }
            if(this.$isEmpty(this.info.alarm_type)){
                return this.$message.error('方案类型不能为空');
            }

            if(this.$isEmpty(this.info.early_warning_balance)){
                return this.$message.error('提前报警余额不能为空');
            }

            if(this.$isEmpty(this.info.alarm_balance)){
                return this.$message.error('报警余额不能为空');
            }
            if(this.$isEmpty(this.info.max_times)){
                return this.$message.error('最大报警次数不能为空');
            }

            if(this.$isEmpty(this.info.alarm_time)){
                return this.$message.error('报警时间间隔不能为空');
            }

            // let api = this.$apiHandle(this.$api.adminUsers,this.id);
            // if(api.status){
                this.$post(this.$api.editAlarmPlanInfo,this.info).then(res=>{
                    if(res.code == 200){
                        this.$message.success(res.msg)
                        return this.$router.back();
                    }else{
                        return this.$message.error(res.msg)
                    }
                })
            // }else{
            //     this.$post(api.url,this.info).then(res=>{
            //         if(res.code == 200){
            //             this.$message.success(res.msg)
            //             return this.$router.back();
            //         }else{
            //             return this.$message.error(res.msg)
            //         }
            //     })
            },


        get_info(){
            this.$get(this.$api.editAlarmPlan+'/'+this.id).then(res=>{
                res.data.password = undefined;
                this.info = res.data;
                this.default_community_id = res.data.community_id;
            })
        },   // 编辑器内容修改
        goods_content_fun(val){
            if(!this.platform){
                this.info.remarks = val;
            }else{
                this.info.remarks_mobile = val;
            }
            this.remarks = val;
        },
        // 编辑器切换平台
        check_platform(status){
            this.platform = status;
            if(!status){
                this.remarks = this.info.remarks??'';
            }else{
                this.remarks = this.info.remarks_mobile??'';
            }
        },
        // 获取列表
        onload(){
            // 判断你是否是编辑
            if(!this.$isEmpty(this.$route.params.id)){
                this.id = this.$route.params.id;
                this.get_info();
            }else{
                this.type='添加';
            }
        },

    },

    created() {
        this.onload();
        // this.getCommunityList();
    },
    mounted() {}
}


</script>
<style lang="scss" scoped>

</style>
